package com.snowRemovingUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.MDeviceAttribute;
import com.snowRemovingUser.service.IMDeviceAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备属性Controller
 * 
 * @author liguang
 * @date 2023-05-14
 */
@RestController
@RequestMapping("/snowRemoving/attribute")
public class MDeviceAttributeController extends BaseController
{
    @Autowired
    private IMDeviceAttributeService mDeviceAttributeService;

    /**
     * 查询设备属性列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(MDeviceAttribute mDeviceAttribute)
    {
        startPage();
        List<MDeviceAttribute> list = mDeviceAttributeService.selectMDeviceAttributeList(mDeviceAttribute);
        return getDataTable(list);
    }

    /**
     * 导出设备属性列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:export')")
    @Log(title = "设备属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MDeviceAttribute mDeviceAttribute)
    {
        List<MDeviceAttribute> list = mDeviceAttributeService.selectMDeviceAttributeList(mDeviceAttribute);
        ExcelUtil<MDeviceAttribute> util = new ExcelUtil<MDeviceAttribute>(MDeviceAttribute.class);
        util.exportExcel(response, list, "设备属性数据");
    }

    /**
     * 获取设备属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:query')")
    @GetMapping(value = "/{serialNumber}")
    public AjaxResult getInfo(@PathVariable("serialNumber") String serialNumber)
    {
        return success(mDeviceAttributeService.selectMDeviceAttributeBySerialNumber(serialNumber));
    }

    /**
     * 新增设备属性
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:add')")
    @Log(title = "设备属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MDeviceAttribute mDeviceAttribute)
    {
        return toAjax(mDeviceAttributeService.insertMDeviceAttribute(mDeviceAttribute));
    }

    /**
     * 修改设备属性
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:edit')")
    @Log(title = "设备属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MDeviceAttribute mDeviceAttribute)
    {
        return toAjax(mDeviceAttributeService.updateMDeviceAttribute(mDeviceAttribute));
    }

    /**
     * 删除设备属性
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:attribute:remove')")
    @Log(title = "设备属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serialNumbers}")
    public AjaxResult remove(@PathVariable String[] serialNumbers)
    {
        return toAjax(mDeviceAttributeService.deleteMDeviceAttributeBySerialNumbers(serialNumbers));
    }
}
